package org.datavis;

import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

import org.datavis.chart.ColumnChart;
import org.datavis.chart.LineChart;
import org.datavis.data.Data;

public class Example extends Activity {
	
	public ColumnChart columnChart;
	public LineChart lineChart;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
     
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.main);
        
        columnChart = (ColumnChart) findViewById(R.id.columnChart);
        lineChart = (LineChart) findViewById(R.id.lineChart);
        
    	Data columnData = new Data();            	
    	String[] columnDesc = {"Google", "Yahoo", "Bing", "Facebook"};            	
    	double[] male = {137, 99, 45, 102};
    	double[] female = {65, 13, 23, 88};
    	double[] all = {202, 112, 68, 190};
    	columnData.setDesc(columnDesc);
    	columnData.addData("male", male);
    	columnData.addData("female", female);
    	columnData.addData("all", all);    	
    	columnChart.setData(columnData);
    	
    	
    	Data lineData = new Data();            	
    	String[] lineDesc = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Okt", "Nov", "Dec"};
    	double google[] = new double[12];
    	double yahoo[] = new double[12];
    	double bing[] = new double[12];
    	double facebook[] = new double[12];
    	
    	double multiplier = 22;
    	double multiplier2 = 12;
    	
    	for (int i = 0; i < 12; i++)
    	{
    		if(Math.random() > 0.5)
    			google[i] = Math.random()*multiplier;
    		else
    			google[i] = -Math.random()*multiplier2;
    		if(Math.random() > 0.5)
    			yahoo[i] = Math.random()*multiplier;
    		else
    			yahoo[i] = -Math.random()*multiplier2;
    		if(Math.random() > 0.5)
    			bing[i] = Math.random()*multiplier;
    		else
    			bing[i] = -Math.random()*multiplier2;
    		if(Math.random() > 0.5)
    			facebook[i] = Math.random()*multiplier;
    		else
    			facebook[i] = -Math.random()*multiplier2;
    	}    	
    	
    	lineData.setDesc(columnDesc);
    	lineData.setDesc(lineDesc);
    	lineData.addData("Google", google);
    	lineData.addData("Yahoo", yahoo);
    	lineData.addData("Bing", bing);
    	lineData.addData("Facebook", facebook);    	
    	lineChart.setData(lineData);
//    	Button myButton = (Button) findViewById(R.id.my_button);
//        myButton.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
//            	
//            	Data data = new Data();
//                double[] test3 = {-2., 3, -6., 1., 4., 12, -1};
//             	double[] test4 = {-1., -1, -2., -1., -2., -1, -9, -3, -5};
//             	double[] test2 = {1., -2.5, 3., 4., -2, -5, 0.3};
//             	String[] sTest = {"schubi", "dubi", "dabu", "Geldor", "rapunzel"};
//             	
//             	data.addData("data", test3);
//             	data.setDesc(sTest);
//
//            	lineChart.setData(data);
//            	columnChart.setData(data);
//            	
//            	Context context = getApplicationContext();
//            	int duration = Toast.LENGTH_SHORT;
//            	
//            	String text = "";
//            	
//            	for (String item: data.getFields())
//            		text += item ;
//            	Toast toast = Toast.makeText(context, text + data.getValues().size(), duration);
//            	toast.show();
//            	//tada.setData(data);
//            }
//        });
        
    }
}